package main

import (
	"fmt"
)

func isMatch1(s string, p string) bool {
	m, n := len(s), len(p)

	matches := func(i, j int) bool {
		if i == 0 {
			return false
		}
		if p[j-1] == '.' {
			return true
		}
		return s[i-1] == p[j-1]
	}

	f := make([][]bool, m + 1)
	for i := 0; i < len(f); i++ {
		f[i] = make([]bool, n + 1)
	}
	f[0][0] = true
	for i := 0; i <= m; i++ {
		for j := 1; j <= n; j++ {
			if p[j-1] == '*' {
				f[i][j] = f[i][j] || f[i][j-2]
				if matches(i, j - 1) {
					f[i][j] = f[i][j] || f[i-1][j]
				}
			} else if matches(i, j) {
				f[i][j] = f[i][j] || f[i-1][j-1]
			}
		}
	}
	return f[m][n]
}

func isMatch2(s string,p string) bool  {
	ret := true
	m,n := len(s),len(p)
	indexs,indexp := 0,0

	for ;indexp<n; {
		if indexs>=m || indexp>=n{
			break
		}
		if indexp+1 < n{
			//* 匹配0个或多个 组合表达式正则前进两格
			if p[indexp+1]==42{
				//. 匹配任意字符
				if p[indexp] == 46{
					indexs = m
					//正则前进两个坐标
					indexp += 2
					break
				}else {
					if indexp+2 < n && p[indexp+2]==p[indexp]{
						numNeed := 0
						indexp += 2
						//多个a* a a* 重复判断
						for ;indexp<n; {
							fmt.Println(indexp)
							if indexp+1>n{
								break
							}
							if indexp+1 == 42{
								if indexp+2 > n || p[indexp+2]!=p[indexp]{
									indexp += 2
									break
								}
								indexp += 2
							}else {
								if p[indexp+1] != p[indexp]{
									indexp++
									break
								}
								numNeed++
								indexp++
							}
						}
						println(numNeed)

					}else {
						for ;indexs<m; {
							if s[indexs] != p[indexp]{
								//fmt.Println("前进两格无法匹配",indexs,indexp,string(s[indexs]),string(p[indexp]))
								break
							}
							indexs++
						}
						//fmt.Println("前进两格正常匹配",indexs,indexp,string(s[indexs]),string(p[indexp]))
						indexp += 2
						continue
					}
				}
			}
		}
		//fmt.Println("前进一格",indexs,indexp,string(s[indexs]),string(p[indexp]))
		//单个表达式 正则前进一格
		if p[indexp]!=46 && s[indexs]!=p[indexp] {
			indexs++
			indexp++
			ret = false
			break
		}
		indexs++
		indexp++
	}

	if ret != false{
		//部分匹配，不能全部匹配
		if indexs<m || indexp<n{
			ret =false
		}
	}

	return ret
}

func isMathc3(s string,p string) bool  {
	m,n := len(s),len(p)

	func matchStr(i int, j int) bool{
		
	}

	f := make([][]bool,m+1)
	for i:=0;i<=m;i++ {
		f[i] = make([]bool,n+1)
	}
	f[0][0] = true //边界情况 "" 和 "" 相等

	for i:=0;i<=m;i++{
		for j:=0;j<=n;j++{

		}
	}

	return f[m][n]
}

func main() {
	//ret := isMatch1("a","aa")
	//fmt.Println(ret)
	//ret2 := isMatch2("aab","c*a*b")
	//ret2 := isMatch2("aaa","a*a")
	//fmt.Println(ret2)

}
